const void* memchr(const void* ptr, int value, int num)
{
	for(; num; num--, ptr++)
		if(*((unsigned char*)ptr) == (unsigned char)value)
			return ptr;

	return 0;
}

int memcmp(const void* ptr1, const void* ptr2, int num)
{
	for(; num; num--)
	{
		int cmp = *((char*)ptr1) - *((char*)ptr2);
		if(cmp) return cmp;

		ptr1++; ptr2++;
	}

	return 0;
}

// Copy len bytes from src to dest.
void memcpy(unsigned char* dest, const unsigned char* src, unsigned int len)
{
    for(; len; len--) *dest++ = *src++;
}

// Write len copies of val into dest.
void memset(unsigned char* dest, unsigned char val, unsigned int len)
{
    for(; len; len--) *dest++ = val;
}

// Copy the NULL-terminated string src into dest up to num, and return dest.
char* strncpy(char* dest, const char* src, unsigned int num)
{
	char* dp = dest;
    for(; num; --num)
    	*dp++ = *src ? *src++ : '\0';
    return dest;
}
